Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-8420: file component no defaults causes error #5642

Merged
merged 2 commits into from
Jun 18, 2024

Conversation

ZenMasterJacob20011
Copy link
Contributor

Link to Jira Ticket

https://formio.atlassian.net/browse/FIO-8420

Description

What changed?

Previously, formio.js would error on a file upload if the noDefaults option in Formio.createForm function was set to true. This PR replaces this behavior by validating that this.dataValue exists before calling the .some function on it.

Why have you chosen this solution?

Although there were many potential solutions my solution was best because it does not cause any new errors/bugs to appear in the code and allows the next couple of lines of code to work without modification.

Dependencies

N/A

How has this PR been tested?

I added automated tests and manually tested

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (if applicable)
  • My changes generate no new warnings
  • My changes include tests that prove my fix is effective (or that my feature works as intended)
  • New and existing unit/integration tests pass locally with my changes
  • Any dependent changes have corresponding PRs that are listed above

@@ -744,7 +744,7 @@ export default class FileComponent extends Field {
const fileWithSameNameUploading = this.filesToSync.filesToUpload
.some(fileToSync => fileToSync.file?.name === file.name);

const fileWithSameNameUploaded = this.dataValue
const fileWithSameNameUploaded = this.dataValue && this.dataValue
.some(fileStatus => fileStatus.originalName === file.name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to make this check even more secure by checking if this.dataValue is an array. Or you can just use lodash, like this:
_.some(this.dataValue, fileStatus => fileStatus.originalName === file.name);
Lodash does all the checking on the incoming value on its own and doesn't throw an error even if this.dataValue is undefine/string/number etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced check with lodash.some function

@TanyaGashtold TanyaGashtold merged commit 4463cff into master Jun 18, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants